/**
 * title: TRACKEDFEATUREDAO_DeleteTestOneFeature.java
 * description: JUnit program that tests the TrackedFeature DAO.
 * date: December 30 2013
 * id: 2540434
 * course: COMP 495 (Project-Server)
 * @author Mohamed B Thaha
 * @version 1.0
 * @copyright 2013 Mohamed B Thaha
 */

/**
 * DOCUMENTATION...
 */

/**                                                                               
 *
 *<H1>TRACKEDFEATUREDAO_DeleteTestOneFeature</H1>
 *
 *<H3>Purpose and Description</H3>
 *
 *<P>
 * An application that uses JUnit unit testing framework.
 *</P>
 *<P>
 * The program's main purpose is to provide sample test cases for specific CRUD
 * operations.
 *</P>
 *<P>
 * This program requires the Sun Java SDK version 1.7 or better.
 *</P>
 *                                                                              
 *<DL>
 *<DT> Compiling and running instructions</DT>
 *<DT> Assuming SDK 1.7 (or later) and the CLASSPATH are set up properly.</DT>
 *<DT> Assuming the use of Eclipse IDE (Kepler) 4.3.1.</DT>
 *<DT> Change to the directory containing the source code.</DT>
 *<DD> Compile:    TRACKEDFEATUREDAO_DeleteTestOneFeature.java</DD>
 *<DD> Run:        TRACKEDFEATUREDAO_DeleteTestOneFeature.java</DD>
 *<DD> Document:   Generate Javadoc TRACKEDFEATUREDAO_DeleteTestOneFeature</DD>
 *</DL>
 */

/**
 *
 * <H3>Classes</H3>
 *
 *<P>
 * public class TRACKEDFEATUREDAO_DeleteTestOneFeature {<BR>
 * This is the main public class for this application. It contains some of the
 * methods required to perform CRUD (test) operations.
 *</P>
 *
 * <H3>TRACKEDFEATUREDAO_DeleteTestOneFeature Methods</H3>
 *
 *<P>
   public void setUp() {<BR>
   This method executes before the desired test method(s) runs; acts as a 
   preliminary setup method.
 *</P>
 *
 *<P>
   public final void testDeleteOneFeature ( ) {<BR>
   This method tests for a successful result provided that the 
   device id, user id, and feature name are correct.
 *</P>
 *
 *<P>
   public final void testDeleteOneFeatureFail ( ) {<BR>
   This method tests for a successful result (failed) provided that the 
   device id, user id, are correct but feature name is incorrect.
 *</P>
 * 
 * <H3>TRACKEDFEATUREDAO_DeleteTestOneFeature Instance Variables</H3>
 *
 *<P>
 * private Date startUsing, endUsing
 * private TrackedFeature trackedFeature
 * private FeatureUsage usage
 * private User userID
 * private Device device
 * private static final long DEVICE_ID = 900
 * private static final long USER_ID = 54
 *</P> 
 */

/**
 *
 * <H3>Test Plan</H3>
 *
 *<P>
 * public final void testDeleteOneFeature() – OK
 * public final void testDeleteOneFeatureFail() - OK
 *</P>
 */

/**
 * CODE...
 */

package athabasca.ca.dao.trackedfeature;
/** Java core packages */
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import java.sql.Date;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import athabasca.ca.model.Device;
import athabasca.ca.model.FeatureUsage;
import athabasca.ca.model.TrackedFeature;
import athabasca.ca.model.User;
import athabasca.ca.dao.TrackedFeatureDAO;
/** primary (public) class for TRACKEDFEATUREDAO_DeleteTestOneFeature */
public class TRACKEDFEATUREDAO_DeleteTestOneFeature {
	private Date startUsing, endUsing;
	private TrackedFeature trackedFeature;
	private FeatureUsage usage;
	private User userID;
	private Device device;
	private static final long DEVICE_ID = 900;
	private static final long USER_ID = 54;
	
	@Before
	public void setUp() {
		userID = new User(USER_ID);
		device = new Device(DEVICE_ID);
		
		// Feature use
		startUsing = new Date(113, 11, 9);
		endUsing = new Date(113, 11, 10);
		
		usage = new FeatureUsage(startUsing, endUsing);
		
		trackedFeature = new TrackedFeature("newFeature", (float) 0);
		trackedFeature.updateUsageHistory(usage);
		
		try {
      	  assertThat ( TrackedFeatureDAO.create(trackedFeature, device.getDeviceId(), userID.getUserId()), is ( true ));
        } catch (Exception e)
        {
            fail ( e.getMessage ( ) );
            e.printStackTrace ( );
        }
	}
	
	@Test
	@Ignore
	public final void testDeleteOneFeature()
	{
		try {
	      	  assertThat ( TrackedFeatureDAO.deleteOneFeature(device.getDeviceId(), userID.getUserId(), trackedFeature), is ( true ));
	        } catch (Exception e)
	        {
	            fail ( e.getMessage ( ) );
	            e.printStackTrace ( );
	        }
	}
	
	@Test
	//@Ignore
	public final void testDeleteOneFeatureFail()
	{
		trackedFeature.setName("noFeature");
		try {
	      	  assertThat ( TrackedFeatureDAO.deleteOneFeature(device.getDeviceId(), userID.getUserId(), trackedFeature), is ( false ));
	        } catch (Exception e)
	        {
	            fail ( e.getMessage ( ) );
	            e.printStackTrace ( );
	        }
	}
} // End of public class TRACKEDFEATUREDAO_DeleteTestOneFeature